package com.mpgame.common.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Log {
    private static final String RESET = "\u001B[0m";
    private static final String RED = "\u001B[31m";
    private static final String YELLOW = "\u001B[33m";
    private static final String GREEN = "\u001B[32m";
    private static final String CYAN = "\u001B[36m";
    private static final String GRAY = "\u001B[37m";

    private static String now() {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date());
    }

    private static String tid() {
        return "tid=" + Thread.currentThread().getId();
    }

    /**
     * 打印信息
     */
    public static void info(String msg) {
        System.out.println(GREEN + "[" + now() + "] [INFO] " + tid() + " " + msg + RESET);
    }

    /**
     * 打印警告
     */
    public static void warn(String msg) {
        System.out.println(YELLOW + "[" + now() + "] [WARN] " + tid() + " " + msg + RESET);
    }

    /**
     * 打印错误
     */
    public static void err(String msg) {
        System.out.println(RED + "[" + now() + "] [ERROR] " + tid() + " " + msg + RESET);
    }

    /**
     * 打印调试信息
     */
    public static void debug(String msg) {
        System.out.println(CYAN + "[" + now() + "] [DEBUG] " + tid() + " " + msg + RESET);
    }

    /**
     * 打印追踪日志
     */
    public static void trace(String msg) {
        System.out.println(GRAY + "[" + now() + "] [TRACE] " + tid() + " " + msg + RESET);
    }
}
